-- if user is "windows" - pull windows users and check membership
-- also pull other relationships


select * from rs_security_GroupRoles
  where GroupName like '%\%'


select * from RS_Security_GroupRoles GR,RS_Security_RolePermissions RP,RS_Security_PersonGroup PG,Persons P
WHERE GR.GroupName = PG.GroupName AND RP.RoleName = GR.RoleName AND P.PersonID = PG.PersonID
 AND Logon = 'tchase'

select email as logon,persons.PersonID 
from ((persons inner join email_addresses on persons.PersonID =  email_addresses.personid)
		inner join email_usage on Email_Usage.EmailID = Email_Addresses.EmailID)
where usage = 'Primary'

(select personid,logon from rs_security_getprimaryemail where not personid in (select personid from persons where not logon is null))
union (select personid,logon from persons where not logon is null)

 select * from Valid_Email_Usage_Types
 select * from persons where personid in ('18856','20081','18288','19655')

 insert into email_usage (EmailID,Usage)
 select emailid,'Primary' from  Email_Addresses

select gui.*,pg.GroupName,rp.RoleName,rp.PermissionName from ((rs_security_getuserinfo gui INNER JOIN RS_Security_PersonGroup pg ON pg.personid = gui.personid)
	Inner JOIN RS_Security_GroupRoles gr on gr.GroupName = pg.GroupName)
	INNER JOIN RS_Security_RolePermissions rp on gr.RoleName = rp.RoleName

select * from rs_security_Groups where GroupName like '%\%'

select gwg.GroupName,gr.RoleName,RP.PermissionName
from (rs_security_getwindowsgroups gwg inner join RS_Security_GroupRoles gr on gwg.GroupName = gr.GroupName)
	  INNER JOIN RS_Security_RolePermissions rp ON RP.RoleName = gr.RoleName

-- Clear Roles
-- Get Windows groups
-- Check Membership
-- Assign roles as needed
-- Get Permissions based on Username
-- Assign roles as needed
-- Alter windows form to create logon without prompting
